package com.qf.java2106.huangshengrui.hotel.dao.impl;

import com.qf.java2106.huangshengrui.hotel.dao.ITableDao;
import com.qf.java2106.huangshengrui.hotel.pojos.Table;
import com.qf.java2106.huangshengrui.hotel.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author q
 * @version V1.0
 * @date 2021/10/30
 **/
public class TableDaoImpl implements ITableDao {

    QueryRunner queryRunner = null;

    @Override
    public List<Table> findAllTable() throws SQLException {
        queryRunner = new QueryRunner(JdbcUtils.getDataSource());
        String sql = "SELECT table_id tableId,table_name tableName,table_status tableStatus,reservation_time reservationTime FROM t_dinner_table";
        return queryRunner.query(JdbcUtils.getConnection(),sql,new BeanListHandler<>(Table.class));
    }

    @Override
    public List<Table> findTableLikeKey(String keyword) throws SQLException {
        queryRunner = new QueryRunner(JdbcUtils.getDataSource());
        String sql = "SELECT table_id tableId,table_name tableName,table_status tableStatus,reservation_time reservationTime FROM t_dinner_table WHERE table_name LIKE ?";
        return queryRunner.query(JdbcUtils.getConnection(),sql,new BeanListHandler<>(Table.class),keyword);
    }
}
